package odesimulation;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;

public class EnzymaticReaction extends Reaction {

	String enzyme;
	
	/**
	 * X + E ==> E + Y + Z + ...
	 * No back reaction rate since enzymatic reaction are irreversible
	 * @param reactant
	 * @param enzyme
	 * @param products
	 * @param reactionRate
	 */
	public EnzymaticReaction(String reactant, String enzyme,
			ArrayList<String> products) {
		super(new ArrayList<String>(), products, 1.0, 0.0);
		super.reactants.add(reactant);
		this.enzyme = enzyme;
	}

	public double computeFlow(String species, double enzymeRate, Map<String,Double> concentrations){
		double flow = reactionRate;
		int count = 0;
		Iterator<String> it = reactants.iterator();
		//Count how much of species is destroyed and compute the actual reaction rate
		while(it.hasNext()){
			String value = it.next();
			if(value.equals(species))
				count--;
			
			flow *= concentrations.get(value);
		}
		it = products.iterator();
		//Count how much of species is destroyed and compute the actual reaction rate
		while(it.hasNext()){
			String value = it.next();
			if(value.equals(species))
				count++;
			
			//flow *= concentrations.get(value);
		}
		//Enzyme
		flow *= enzymeRate;
		
		return count*flow;
	}
	
}
